package com.ynny.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;

@Repository
public class AccountDaoImpl implements AccountDao {

    @Autowired
    JdbcTemplate jdbcTemplate;

    @Override
    public int addAccountBalance(String carId, BigDecimal money) {


        String sql = "update account set balance=balance+? where cardId=?";
        int i = jdbcTemplate.update(sql, money, carId);


        return i;
    }

    @Override
    public int subAccountBalance(String carId, BigDecimal money) {

        String sql = "update account set balance=balance - ? where cardId=?";
        int i = jdbcTemplate.update(sql, money, carId);
        return i;
    }
}
